Computer Graphics Linear Algebra Review
CG-Math-Review
Vectors
Vectors are mathematical objects that have both a magnitude (size) and a direction. They are widely used in computer graphics for representing points, directions, velocities, and more in 2D, 3D, or higher-dimensional spaces.
Vector Normalization
Normalization is the process of converting a vector to a unit vector (a vector with a magnitude of 1) while maintaining its direction. This is often useful in shading calculations or directional movement.
To normalize a vector v:
Where:
is the original vector. is the magnitude (or length) of the vector, calculated as:
Cartesian coordinates are used to describe points in a 2D or 3D space as tuples of numbers (x, y) or (x, y, z). In vector representation, they are used to describe the components of a vector.
For example:
- A point in 2D space:
- A point in 3D space:
Vector Multiplication
Vector multiplication comes in three major forms:
- Scalar (dot) product: Produces a scalar value, useful for projections.
- Vector (cross) product: Produces a new vector orthogonal to the two input vectors.
- Scalar multiplication: A vector is multiplied by a scalar value.
Dot (Scalar) Product
The dot product of two vectors produces a single scalar value and is a measure of how much one vector extends in the direction of another. It is calculated using:
Dot Product for Projection
The dot product can also be used to compute the projection of one vector onto another:
In vector form, the projected vector is:
Cross (Vector) Product
In 3D, the cross product of two vectors produces a new vector that is perpendicular to both of the input vectors. The magnitude of the result is equal to the area of the parallelogram formed by the two vectors.
Where
Cross Product: Properties
(zero vector) - The magnitude of the cross product is:
Where is the angle between the vectors. - The direction of the resultant vector follows the right-hand rule.
Orthonormal Coordinate Frames
An orthonormal coordinate frame is a set of basis vectors that are:
- Orthogonal: Each pair of vectors is perpendicular.
- Normalized: Each basis vector has a magnitude of 1.
In 3D computer graphics, orthonormal frames (like the basis vectors
Matrix
A matrix is a 2D array of numbers that can represent a variety of transformations or systems of equations. In computer graphics, matrices are widely used to perform linear transformations like scaling, rotation, and translation.
Matrix-Matrix Multiplication
The product of two matrices
Matrix-Vector Multiplication
A matrix can transform a vector by the operation
Example: For
Transpose of a Matrix
The transpose of a matrix
Identity Matrix and Inverses
Identity Matrix: An identity matrix
is a square matrix with 1s on the diagonal and 0s elsewhere: Inverse Matrix: For a square matrix
, the inverse satisfies: Not all matrices have inverses; a matrix must be non-singular (determinant
).
Vector Multiplication in Matrix Form
The dot product of two vectors can also be represented as a matrix multiplication:
For example: